Population class extension: spacing_functions module

Module containing the spacing functions for the binarycpython package. Very under-populated at the moment, but more are likely to come soon

This class object is an extension to the population grid object

Tasks:

TODO: add more spacing functions to this module.

class binarycpython.utils.population_extensions.spacing_functions.spacing_functions(**kwargs)[source]

Bases: object

Extension for the Population class containing the code for spacing functions

const_dt(cachedir=None, usecache=True, **kwargs)[source]

const_dt returns a list of masses spaced at a constant age difference

Parameters
  • dt – the time difference between the masses (1000.0 Myr, used when logspacing==False)

  • dlogt – the delta log10(time) difference between masses (0.1 dex, used when logspacing==True)

  • mmin – the minimum mass to be considered in the stellar lifetime interpolation table (0.07 Msun)

  • mmax – the maximum mass to be considered in the stellar lifetime interpolation table (100.0 Msun)

  • nres – the resolution of the stellar lifetime interpolation table (100)

  • logspacing – whether to use log-spaced time, in which case dt is actually d(log10(t))

  • tmin – the minimum time to consider (Myr, default 3.0 Myr)

  • tmax – the maximum time to consider (Myr, default None which means we use the grid option ‘max_evolution_time’)

  • max_evolution_time – overrides bse_options[‘max_evolution_time’] if set

  • mindm – a tuple of tuples containing a mass range and minimum mass spacing in that range. The default is ((0.07,1.0,0.1),(1.0,300.0,1.0)) allocated a minimum dm of 0.1Msun in the mass range 0.07 to 1.0 Msun and 1.0Msun in the range 1.0 to 300.0 Msun. Anything you set overrides this. Note, if you use only one tuple, you must set it with a trailing comma, thus, e.g. ((0.07,1.0,0.1),). (default None)

  • maxdm – a list of tuples similar to mindm but specifying a maximum mass spacing. In the case of maxdm, if the third option in each tuple is negative it is treated as a log step (its absolute value is used as the step). (default None)

  • fsample – a global sampling (Shannon-like) factor (<1) to improve resolution (default 1.0, set to smaller to improve resolution)

  • factor – all masses generated are multiplied by this after generation

  • showtable – if True, the mass list and times are shown to stdout after generation

  • showlist – if True, show the mass list once generated

  • logmasses – if True, the masses are logged with math.log()

  • log10masses – if True, the masses are logged with math.log10()

  • usecache – if True (the default) uses cached results if they are saved (in cachedir) and cachedir is not None

  • cachedir – where the cache is stored. if None, defaults to population_options[‘cache_dir’]+’/const_dt_cache’

  • vb – verbose logging flag (default False)

Returns

Array of masses.

Example

these are lines set as options to Population.add_grid_value(…):

# linear time bins of 1Gyr
samplerfunc="self.const_dt(self,dt=1000,nres=100,mmin=0.07,mmax=2.0,showtable=True)"

# logarithmic spacing in time, generally suitable for Galactic chemical evolution yield grids.
samplerfunc="self.const_dt(self,dlogt=0.1,nres=100,mmin=0.07,mmax=80.0,maxdm=((0.07,1.0,0.1),(1.0,10.0,1.0),(10.0,80.0,2.0)),showtable=True,logspacing=True,fsample=1.0/4.0)"
const_int(min_bound, max_bound, steps)[source]

Samples an integer range linearly. Returns a list of ints.

Parameters
  • min_bound (Union[int, float]) – lower bound of range, must be an integer (is converted to int)

  • max_bound (Union[int, float]) – upper bound of range, must be an integer (is converted to int)

  • steps (int) – number of segments between min_bound and max_bound

Return type

list

Returns

range(min_bound,max_bound,step)

where step is int((int(max_bound)-int(min_bound))/steps)

const_linear(min_bound, max_bound, steps)[source]

Samples a range linearly. Uses numpy linspace, and returns an array of floats. Do NOT use this for integers.

Parameters
  • min_bound (Union[int, float]) – lower bound of range

  • max_bound (Union[int, float]) – upper bound of range

  • steps (int) – number of segments between min_bound and max_bound

Return type

list

Returns

np.linspace(min_bound, max_bound, steps)

const_ranges(ranges)[source]

Samples a series of ranges linearly.

Parameters

ranges – a tuple of tuples passed to the self.const_linear() spacing function.

Return type

list

Returns

numpy array of masses

Example

The following allocates 10 stars between 0.1 and 0.65, 20 stars between 0.65 and 0.85, and 10 stars between 0.85 and 10.0 Msun:

samplerfunc="const_ranges((({},{},{}),({},{},{}),({},{},{})))".format(
    0.1, 0.65, 10,
    0.65, 0.85, 20,
    0.85, 10.0, 10
)
gaussian_zoom(min_bound, max_bound, zoom_mean, zoom_dispersion, zoom_magnitude, steps)[source]

Samples such that a region is zoomed in according to a 1-Gaussian function

Parameters
  • min_bound (Union[int, float]) – lower bound of range

  • max_bound (Union[int, float]) – upper bound of range

  • zoom_mean (Union[int, float]) – mean of the Gaussian zoom location

  • zoom_dispersion (Union[int, float]) – dispersion of the Gaussian

  • zoom_magnitude (Union[int, float]) – depth of the Gaussian (should be 0<= zoom_magntiude <1)

  • steps (int) – number of segments between min_bound and max_bound assuming a linear step this is what you’d normally call “resolution”

Return type

list

Returns

Numpy array of sample values

peak_normalized_gaussian_func(x, mean, sigma)[source]

Function to evaluate a Gaussian at a given point, note that the normalization is such that the peak is always 1.0, not that the integral is 1.0

Parameters
  • x (Union[int, float]) – location at which to evaluate the distribution

  • mean (Union[int, float]) – mean of the Gaussian

  • sigma (Union[int, float]) – standard deviation of the Gaussian

Return type

Union[int, float]

Returns

value of the Gaussian at x